﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SKDB_Matcher
{
    public partial class CAlternativeColDlg : Form
    {
        const int MAX_COLUMNS = 10;

        DataColumn[] m_Columns;
        int ID = -1;

        float[] m_Matchings;
        public CAlternativeColDlg(DataColumn[] _Columns, float[] _Matchings)
        {
            InitializeComponent();
            m_Columns = _Columns;
            m_Matchings = _Matchings;
            Show();
        }

        private void Show(Boolean ShowAll = false)
        {
            lbColumns.Items.Clear();
            int Counter = 0;
            for (int i = 0; i < m_Columns.Length; i++)
            {
                if (m_Matchings[i] >= 0.25f)
                {
                    lbColumns.Items.Add(m_Columns[i].Table.TableName + " \\ " + m_Columns[i].ColumnName + " (" + m_Columns[i].DataType.Name + ")" + " [" + ((int)(m_Matchings[i] * 100f)).ToString() + "%]");
                    Counter++;
                    if (Counter >= MAX_COLUMNS && !ShowAll)
                        break;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Show(true);
        }

        public DataColumn GetSelectedCol()
        {
            if (ID >= 0)
            {
                return m_Columns[ID];
            }
            else
                return null;
        }

        public float GetSelectedMatching()
        {
            if (ID >= 0)
            {
                return m_Matchings[ID];
            }
            else
                return -1;
        }

        private void lbColumns_SelectedIndexChanged(object sender, EventArgs e)
        {
            ID = lbColumns.SelectedIndex;
        }

        private void OkBtn_Click(object sender, EventArgs e)
        {

        }
        
    }
}
